-- SELECT dbo.fn_getShipping_fgProcessStep_id ( 3681 )
-- drop function fn_getShipping_fgProcessStep_id
 
CREATE  FUNCTION fn_getShipping_fgProcessStep_id( @productId INT )
RETURNS INT AS 
BEGIN
	DECLARE @fgProcessStepId INT 
	DECLARE @parentProductId INT
	DECLARE @pType VARCHAR(50)

	SET @fgProcessStepId = -1
	SELECT @fgProcessStepId = processstep_id, @pType = P_Type, @parentProductId = P_Parent_Product_ID FROM product WHERE Product_Id = @productId
	
	IF( @pType <> 'CHIP' )
	BEGIN
	 	IF( @parentProductId != -1)
 		BEGIN	
 			SELECT @fgProcessStepId = processStep_ID FROM product WHERE Product_id = @parentProductId
	 	END
 	END
	RETURN @fgProcessStepId
END
